#/bin/bash

#Following is color code
REDBRIGHT=91m
GEENBRIGHT=92m
YELLOWBRIGHT=93m
BLUEBRIGHT=94m

color(){
    local c=$1
    local m=$2
    # echo "m is $m"
    case $c in
        r) m=("\x1B[${REDBRIGHT}${m}\x1B[39m")
        ;;
        g) m=("\x1B[${GEENBRIGHT}${m}\x1B[39m")
        ;;
        y) m=(\x1B[${YELLOWBRIGHT}${m}\x1B[39m)
        ;;
        b) m=("\x1B[${BLUEBRIGHT}${m}\x1B[39m")
        ;;
    esac
    echo $m
}
LOG_ECHO(){
    local level=$1
    local message=$2
    
    local ld=$(date +' %Y-%m-%d %H:%M:%S')
    ld=$(color b $ld)
    echo -e "[${ld}]$level $message" 1>&2
}

LOG_ERROR(){
    local level=$(color r "[ERROR]")
    LOG_ECHO "$level" "$1"
}

LOG_DEBUG(){
    # color g "[ INFO]"
    # echo $1
    local level=$(color g "[ INFO]")
    # echo -e $level
    LOG_ECHO "$level" "$1"
}